/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package business.adapter.TextChanges;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import models.TextChanges;

/**
 *
 * @author dfsljhgsdlfka
 */
public class TextChangesAdapterSingleton {

    private JTextArea jta;
    private static TextChangesAdapterSingleton tca;

    private TextChangesAdapterSingleton() {
    }

    public static TextChangesAdapterSingleton getInstance() {
        if (tca == null) {
            tca = new TextChangesAdapterSingleton();
        }
        return tca;
    }

    public void setJTextArea(JTextArea jta) {
        this.jta = jta;
    }

    public void changeTextArea(final TextChanges tc) {
        SwingUtilities.invokeLater(new Runnable() 
        {
            @Override
            public void run()
            {
                tc.getChanges();
                if (tc.isType())
                    jta.insert(tc.getText(), tc.getOffset());
                else
                    jta.replaceRange("", tc.getOffset(), tc.getOffset() + tc.getSize());
            }
                
            
        });
    }
}
